<?php
namespace app\libs;

class Validator {

    static function validateNickname($nick) {
        // if( false !== strpos($nick, "'") ) {
            // return false;
        // }

        if( false !== strpos($nick, '>') || false !== strpos($nick, '<') ) {
            return false;
        }

        if( 1 === preg_match('/^[_A-Za-z0-9\-\x{4e00}-\x{9fa5}]+$/u', $nick) ) {
            return true;
        }

        return false;
    }

    static function validateEmail($email) {
        if(1 === preg_match('/^[A-Za-z0-9_\-]+\@[A-Za-z0-9\-]+\.[a-zA-Z0-9]{2,4}$/', $email)) {
            return true;
        }

        return false;
    }

    static function permittedEmail($email) {
        $permit = \Fate::$app->iniReader->get('system', 'permit_emails');
        $arr = explode(',', $permit);  // ['@qq.com', '@126.com']
        $ret = false;

        foreach($arr as $val) {
            if( false !== strpos($email, $val) ) {
                $ret = true;
                break;
            }
        }

        return $ret;
    }

}
